import { Ref, ref } from "vue";
import { controlDevice } from "../shared";

/*
 * @Author: ReinerLau lk850593913@gmail.com
 * @Date: 2023-02-03 16:34:53
 * @LastEditors: ReinerLau lk850593913@gmail.com
 * @LastEditTime: 2023-02-03 16:38:29
 * @FilePath: \v2.0.0\src\views\patroling\composables\useAwayControl.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
interface Options {
  caritem: Ref<string>;
}
export default (options: Options) => {
  const { caritem } = options;
  const playBirdAway = ref(false);
  const playPersonAway = ref(false);
  function toggleAudioPause() {
    const data = {
      code: caritem.value,
      param1: "05",
      param2: "03",
      param3: "255",
      param4: "ff",
    };
    controlDevice(data);
  }
  function toggleBirdAway() {
    playBirdAway.value = !playBirdAway.value;
    if (playBirdAway.value) {
      const data = {
        code: caritem.value,
        param1: "05",
        param2: "01",
        param3: "255",
        param4: "ff",
      };
      controlDevice(data);
    } else {
      toggleAudioPause();
    }
  }
  function togglePersonAway() {
    playPersonAway.value = !playPersonAway.value;
    if (playPersonAway.value) {
      const data = {
        code: caritem.value,
        param1: "05",
        param2: "02",
        param3: "255",
        param4: "ff",
      };
      controlDevice(data);
    } else {
      toggleAudioPause();
    }
  }

  return {
    toggleAudioPause,
    toggleBirdAway,
    togglePersonAway,
  };
};
